package cj.web.sc.dao;
/*
 *  
 *  
*/
import java.util.List;
import java.util.Map;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.sc.domain.SCProperty;

/**
 * 
 * @author 
 *
 */
@DAO
public interface SCPropertyDAO{
    @SQL("select * from SCProperty where id=:1")
    SCProperty queryById(int id);
    
    @SQL("INSERT INTO SCProperty (categoryId,name,descs,type,isUsrDefn,sort,deleteFlag,createUser,createAt,updateUser,updateAt) VALUES (:t.categoryId,:t.name,:t.descs,:t.type,:t.isUsrDefn,:t.sort,:t.deleteFlag,:t.createUser,NOW(),:t.updateUser,NOW())")
    void create(@SQLParam("t") SCProperty sCProperty);
	
	@SQL("UPDATE SCProperty SET name=:t.name,descs=:t.descs,type=:t.type,isUsrDefn=:t.isUsrDefn,sort=:t.sort,updateUser=:t.updateUser,updateAt=NOW() WHERE id=:t.id")
    void update(@SQLParam("t") SCProperty sCProperty);
    
    @SQL("UPDATE SCProperty SET deleteFlag=0,updateUser=:t.updateUser,updateAt=NOW() WHERE id=:t.id")
    void deleteById(@SQLParam("t") SCProperty sCProperty);

    @SQL("select a.id,a.name,b.name as categoryName,a.type,a.isUsrDefn,a.sort from SCProperty a join SCCategory b on a.categoryId=b.id and b.deleteFlag=1 where a.deleteFlag=1 #if(:t.categoryId!=-1){ and a.categoryId=:t.categoryId } ORDER BY a.categoryId,b.sort,a.sort limit :t.start,:t.length")
	List<Map> queryByCategory(@SQLParam("t") SCProperty property);

    @SQL("select count(0) from SCProperty a join SCCategory b on a.categoryId=b.id and b.deleteFlag=1 where a.deleteFlag=1 #if(:t.categoryId!=-1){ and a.categoryId=:t.categoryId }")
	int sizeByCategory(@SQLParam("t") SCProperty property);

    @SQL("select id,name,isUsrDefn from SCProperty where deleteFlag=1 and categoryId=:1 order by sort")
	List<Map> queryByCategoryId(int categoryId);
}